package com.knowledge.action;

import java.sql.*;
import java.util.*;

import com.knowledge.DAO.DBpool;
import com.knowledge.model.*;

import com.opensymphony.xwork2.ActionSupport;

public class LabelKnowledgeListAction extends ActionSupport {
	
	String labelId;
	String userId;
	private List<Knowledge> knowledgelist = new ArrayList<Knowledge>();
	private Connection con=null;
	private Statement smt=null;
	private ResultSet rs=null;
	

	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		String sql="select * from label_knowledge lk,knowledge k "
					+" where lk.knowledgeId=k.id "
					+" and lk.labelId='"+labelId+"'";
		
		con = DBpool.getConnection();
		smt=con.createStatement();
		rs=smt.executeQuery(sql);
	
		
		while(rs.next())
		{
			Knowledge knowledge= new Knowledge();
			
			knowledge.setId(Integer.toString(rs.getInt("id")));
			knowledge.setTitle(rs.getString("title"));
			knowledge.setSummary(rs.getString("summary"));
			knowledge.setContent(rs.getString("content"));
			knowledge.setAddData(rs.getDate("addTime"));
			
			knowledgelist.add(knowledge);
		}
		
		return SUCCESS;
	}

	public String getLabelId() {
		return labelId;
	}

	public void setLabelId(String labelId) {
		this.labelId = labelId;
	}

	

	public List<Knowledge> getKnowledgelist() {
		return knowledgelist;
	}

	public void setKnowledgelist(List<Knowledge> knowledgelist) {
		this.knowledgelist = knowledgelist;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}
	

}
